#include<func.h>

typedef struct node
{
    int num;
    struct  node* next; //指向下一个节点
}Node;
typedef struct list
{
    int length;
    Node*Phead;
    Node*PTail;
}List;
//尾插法
int Inset(List *list,int num)
{
    //判断是否为0
    Node *pNew = (Node*)malloc(sizeof(Node));
    //附值
    pNew->num = num;
    pNew->next=NULL;//如果是用calloc就可以不用这一步
    //此时队伍为0
    if(list->length == 0)
    {
        //头部和尾部都指向pNew 啊啊这里写错了 是= 不是==
        list->Phead=pNew;
        list->PTail=pNew;
    }
    else
    {
        //找到尾部节点
        list->PTail->next = pNew;
        list->PTail=pNew;
    }
    //记得要加size
    list->length++;
    return 0;
}



//遍历链表
int Visit(List*list)
{
    Node*pTemp = list->Phead;
    while(pTemp)
    {
        printf("node num is %d\n",pTemp->num);
        pTemp = pTemp->next;
    }
    printf("\n");
    return 0;
}

void* pthread(void*args)
{
    List *list = (List*)args;
    Visit(list);
}

int main(void)
{
    //创建链表
    List list;
    memset(&list,0,sizeof(list));
    for(int i=0;i<10;i++)
    {
        Inset(&list,i);
    }
    //Visit(&list);

    pthread_t td1;
    //传链表到子线程
    pthread_create(&td1,NULL,pthread,&list);
    pthread_join(td1,NULL);
    return 0;
}